package logic

import (
	"ball/ballrpc/ballrpc"
	"ball/ballrpc/internal/svc"
	"ball/models/mysql"
	"context"

	"github.com/zeromicro/go-zero/core/logx"
)

type PostAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPostAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PostAddLogic {
	return &PostAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 发布帖子
func (l *PostAddLogic) PostAdd(in *ballrpc.PostAddRequest) (*ballrpc.PostAddResponse, error) {
	// todo: add your logic here and delete this line
	post := mysql.Post{
		Title: in.Title,
		Desc:  in.Desc,
	}
	mysql.DB.Debug().Create(&post)
	return &ballrpc.PostAddResponse{
		Id: int64(post.ID),
	}, nil
}
